﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Telerik.Web.UI;


namespace BEGDC.CC.Web.Common
{
    public partial class SelectSingleUser : System.Web.UI.Page
    {
        //protected void Page_Load(object sender, EventArgs e)
        //{
        //    if (!Page.IsPostBack)
        //    {
        //        imgClose.Src = "~/App_Themes/" + this.Theme + "/Images/close_top.jpg";
        //        IntiBG();
        //        BindDataToGrid();

        //        if (Request["AllowEmpty"] != null)
        //        {
        //            hidAllowEmpty.Value = Request["AllowEmpty"].ToString() == "1" ? "1" : "";
        //        }
        //        else
        //        {
        //            hidAllowEmpty.Value = "";
        //        }
        //    }

        //}

        //public DataTable DTBDandDep
        //{
        //    get
        //    {
        //        return this.ViewState["DTBDandDep"] != null ? (DataTable)this.ViewState["DTBDandDep"] : null;
        //    }
        //    set
        //    {
        //        this.ViewState["DTBDandDep"] = value;
        //    }
        //}

        ///// <summary>
        ///// 初始化一级部门
        ///// </summary>
        //private void IntiBG()
        //{
        //    SelectUsersBusiness bs = new SelectUsersBusiness();
        //    DataTable dt = bs.GetBG("");
        //    if (dt.Rows.Count > 0)
        //    {
        //        ddlBG.DataSource = dt.DefaultView;
        //        ddlBG.DataTextField = "PARTY_NAME";
        //        ddlBG.DataValueField = "PARTY_ID";
        //        ddlBG.DataBind();
        //    }
        //    Vela3Utility.DownListSetText(ddlBG, Common.CCD, ddlBG.SelectedItem.Text);
        //    IntiBD();
        //    ddlBG.Items.Insert(0, new ListItem("         ", "-1"));

        //}

        ///// <summary>
        ///// 初始化二级部门
        ///// </summary>
        //private void IntiBD()
        //{
        //    DTBDandDep = null;
        //    SelectUsersBusiness bs = new SelectUsersBusiness();
        //    DTBDandDep = bs.GetBDAndDEP(ddlBG.SelectedValue, "");
        //    string bg = ddlBG.SelectedValue;
        //    DataSet dsBD = new DataSet();
        //    DataTable dtBD = new DataTable();
        //    if (DTBDandDep != null)
        //    {
        //        dtBD = DTBDandDep.Clone();
        //        dsBD.Tables.Add(dtBD);
        //        dsBD.Merge(DTBDandDep.Select(string.Format(" PARTY_PARENT={0}", bg)));
        //        this.ddlBD.DataSource = dsBD.Tables[0].DefaultView;
        //        this.ddlBD.DataTextField = "PARTY_NAME";
        //        ddlBD.DataValueField = "PARTY_ID";
        //        ddlBD.DataBind();
        //        ddlBD.Items.Insert(0, new ListItem("", ""));
        //    }
        //}

        ///// <summary>
        ///// 初始化三级部门
        ///// </summary>
        //private void IntiDEP()
        //{
        //    string bd = ddlBD.SelectedValue.Trim();
        //    DataSet dsDEP = new DataSet();
        //    DataTable dtDEP = new DataTable();
        //    if (DTBDandDep != null && bd.Length > 0)
        //    {
        //        dtDEP = DTBDandDep.Clone();
        //        dsDEP.Tables.Add(dtDEP);
        //        dsDEP.Merge(DTBDandDep.Select(string.Format(" PARTY_PARENT={0}", bd)));
        //        ddlDEP.DataSource = dsDEP.Tables[0].DefaultView;
        //        ddlDEP.DataTextField = "PARTY_NAME";
        //        ddlDEP.DataValueField = "PARTY_ID";
        //        ddlDEP.DataBind();
        //        ddlDEP.Items.Insert(0, new ListItem("", ""));
        //    }
        //    else
        //    {
        //        ddlDEP.Items.Clear();
        //    }
        //}
        //#region Web Form Designer generated code
        //protected void rgSelectUser_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        //{
        //    if (e.RebindReason == GridRebindReason.ExplicitRebind ||
        //        e.RebindReason == GridRebindReason.PostBackEvent)
        //    {
        //        //VelaGrid grid = ((VelaGrid)source);
        //        //grid.RefreshDataCount();
        //        //DataSet ds = grid.GetOptimizeDataSouce();
        //        //grid.DataSource = ds.Tables[0].DefaultView; 
        //    }
        //}
        //#endregion


        //protected void rgSelectUser_OnSortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)
        //{
        //    ucPager.Sort(e);
        //}

        //protected void ucPager_OnNeedDataSource(object sender, PagerEventArgs e)
        //{
        //    object count = 0;
        //    SelectUsersBusiness bs = new SelectUsersBusiness();
        //    ucPager.DataSource = bs.GetSelectUserInfo(e.IsLast, ucPager.SortString, ucPager.PageIndex, ucPager.PageSize, this.Filter, ref count);
        //    // ucPager.DataSource = Vela3Utility.SelectDataForSearchPage("role", ucPager.SortString, ucPager.PageIndex, ucPager.PageSize, ref count, "*", this.Filter, e.IsLast).Tables[0];
        //    ucPager.RowsCount = (int)count;

        //}

        //#region 绑定角色数据
        //private string Filter
        //{
        //    get
        //    {
        //        if (ViewState["Filter"] == null)
        //        {
        //            return string.Empty;
        //        }
        //        return ViewState["Filter"].ToString();
        //    }
        //    set
        //    {
        //        ViewState["Filter"] = value;
        //    }
        //}

        //private void BindDataToGrid()
        //{
        //    this.Filter = string.Empty;
        //    string user_cd = this.txtUSER_CD.Text.Trim();
        //    string user_name = txtUSER_NAME.Text.Trim();
        //    string PARTY_PARENT = ddlBD.Items.Count > 0 ? ddlBD.SelectedValue : string.Empty;
        //    string HR_PARTY_ID = ddlDEP.Items.Count > 0 ? ddlDEP.SelectedValue : string.Empty;
        //    string bgid = ddlBG.SelectedValue;
        //    if (user_cd.Length > 0)
        //        this.Filter += string.Format(" AND  USER_CD like '%{0}%' ", user_cd);
        //    if (user_name.Length > 0)
        //        this.Filter += string.Format(" AND ([USER_NAME] LIKE '%{0}%'   OR ENGLISH_NAME LIKE '%{0}%'   OR ACCOUNT LIKE  '%{0}%' )", user_name);
        //    if (bgid != "-1")
        //    {
        //        if (PARTY_PARENT.Length > 0)
        //            this.Filter += string.Format(" AND PARTY_PARENT ={0}", PARTY_PARENT);
        //        else
        //            this.Filter += string.Format(" AND PARTY_PARENT in ({0})", GetBDIDs(bgid));
        //    }
        //    if (HR_PARTY_ID.Length > 0)
        //        this.Filter += string.Format(" AND HR_PARTY_ID = {0}", HR_PARTY_ID);
        //    //SET @SQL_CONDTION =' AND A.USER_CD LIKE ''%' + @USER_CD + '%'''

        //    //IF (NOT @USER_NAME IS NULL) AND LEN(@USER_NAME) > 0
        //    //BEGIN
        //    //    SET @SQL_CONDTION = @SQL_CONDTION 
        //    //        + ' AND (A.[USER_NAME] LIKE ''%' + @USER_NAME + '%'' OR A.ENGLISH_NAME LIKE ''%' 
        //    //        + @USER_NAME + '%'' OR A.ACCOUNT LIKE ''%' + @USER_NAME + '%'')' 
        //    //END 

        //    //SET @SQL_CONDTION = @SQL_CONDTION + ' AND PARTY_PARENT IN (' + @PARTY_PARENT + ')'
        //    //SET @SQL_CONDTION = @SQL_CONDTION + ' AND A.HR_PARTY_ID IN (' + @HR_PARTY_ID + ')'

        //    ucPager.Query();


        //}

        ///// <summary>
        ///// 获取二级部门ID
        ///// </summary>
        ///// <returns></returns>
        //private string GetBDIDs(string bgid)
        //{
        //    string bdids = string.Empty;
        //    ResourceRequestCandidateBusiness rrcb = new ResourceRequestCandidateBusiness();
        //    DataTable dt = rrcb.GetBDID(bgid);
        //    foreach (DataRow dr in dt.Rows)
        //        bdids += dr["party_id"] + ",";
        //    if (bdids.Length > 0)
        //        bdids = bdids.TrimEnd(',');
        //    return bdids;

        //}


        //#endregion

        //#region 查询
        //protected void btnSearch_Click(object sender, EventArgs e)
        //{
        //    BindDataToGrid();
        //}
        //#endregion

        ////#region 保存
        ////protected void btnSave_Click(object sender, EventArgs e)
        ////{
        ////    string userids = string.Empty;

        ////    foreach (GridItem row in rgSelectUser.Items)
        ////    {
        ////        Label lbl = row.FindControl("lbluserid") as Label;
        ////        CheckBox chk = row.FindControl("ckbItem") as CheckBox;
        ////        if (chk.Checked)
        ////        {
        ////            userids += lbl.Text + ",";

        ////            // SkillsetUserEdit skillsetUserEdit = new SkillsetUserEdit();
        ////            // skillsetUserEdit.InsertOrUpdateUserSkillSetMapping(SKILLSET_ID, UserInfo.USER_ID, lbl.Text);
        ////        }
        ////    }
        ////    string script = "window.opener.RefreshUserID('" + userids.TrimEnd(',') + "');window.close();";
        ////    ScriptManager.RegisterClientScriptBlock(this.Page, typeof(Page), "RefreshUserID", script, true);

        ////}
        ////#endregion

        ///// <summary>
        ///// 一级部门选择事件
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //protected void ddlBG_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    if (ddlBG.SelectedValue == "-1")
        //    {
        //        ddlBD.Items.Clear();
        //        ddlDEP.Items.Clear();
        //        return;
        //    }
        //    IntiBD();
        //    if (ddlDEP.Items.Count > 0)
        //        ddlDEP.Items.Clear();
        //}

        ///// <summary>
        ///// 二级部门选择事件
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //protected void ddlBD_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    IntiDEP();
        //}
    }
}
